#include "GameActions.h"
#include "..\Constants.h"
// ------------------------------------------------
//
// ------------------------------------------------
void UpdateBackgroundAction::update(float elapsed) {
	m_Timer += elapsed;
	ds::Vec3 position = ds::Vec3(
		cos(m_Timer / starsParallaxPeriod),
		sin(m_Timer / starsParallaxPeriod),
		0.0f) *
		starsParallaxAmplitude;	
	ds::Shader& shader = gEngine->getResourceManager().getShader(m_ShaderHandle);
	shader.setVec3("position",position);
	shader.setFloat("timer",m_Timer);
}

// ------------------------------------------------
//
// ------------------------------------------------
void MouseAction::OnButtonUp( int button ) {
	if ( isActive() ) {
		if ( button == 0 ) {
			m_Core->block().convert();		
		}
		if ( button == 1 ) {
			m_Core->block().rotateColors();
		}
	}
}

// ------------------------------------------------
//
// ------------------------------------------------
void ShowGridAction::start() {
	m_Core->score().points = 0;
	m_Core->score().coverage = 0;
	m_Core->score().level = m_Core->settings().level;
	m_Core->hud().reset();
	m_Core->hud().setActive(true);
	ds::WorldLayer wl = gEngine->getWorld().getLayerByName("HUD");
	gEngine->getWorld().activateLayer(wl);
	m_Core->gutter().loadTextLevel(m_Core->settings().level);
	m_Core->map().reset();
	m_Core->map().setActive(true);
	m_Core->block().setActive(true);
}

void ShowGridAction::stop() {
	m_Core->hud().setActive(false);
	m_Core->map().reset();
	m_Core->map().setActive(false);
	m_Core->block().setActive(false);
	ds::WorldLayer wl = gEngine->getWorld().getLayerByName("HUD");
	gEngine->getWorld().deactivateLayer(wl);
	m_Core->block().setActive(false);
	m_Core->gutter().reset();
	m_Core->gutter().setActive(false);
}


